<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>餐厅点餐管理</title>
    <!-- 引入Bootstrap CSS框架 -->
    <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet">
    <style>
        body {
            padding-top: 20px;
            background-color: #f8f9fa;
        }
        .container {
            padding: 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }
        .table {
            margin-top: 20px;
        }
        .form-wrapper {
            margin-top: 20px;
        }
        .btn-add-to-cart {
            background-color: #28a745;
            border-color: #28a745;
        }
        .btn-add-to-cart:hover {
            background-color: #218838;
            border-color: #1e7e34;
        }
        /* 其他自定义样式 */
    </style>
</head>
<body>

<div class="container">
    <h2>所有菜品名称价格</h2>
    <a href="edit.jsp">增加菜品</a>
    <!-- 其他会话属性 -->
    <%
    String restaurant_id = (String) session.getAttribute("restaurant_id");
    String table_id = (String) session.getAttribute("table_id");
    %>

    <table width="100%" border="1">
        <tr>
            <th>ID</th>
            <th>菜品名称</th>
            <th>价格</th>
        </tr>
        <% 
        javax.sql.rowset.WebRowSet rs = null;
        try {
            rs = com.myweb.DBTools.getRS("SELECT * FROM dishes where restaurant_id=" + restaurant_id);
            while (rs.next()) {
                String dish_id = rs.getString("dish_id");
                String name = rs.getString("name");
                String price = rs.getString("price");
        %>
        <tr onclick="fillform(this)" style="cursor:pointer">
            <td><%= dish_id %></td>
            <td><%= name %></td>
            <td><%= price %></td>
        </tr>
        <% 
            }
        } finally {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    // 异常处理
                    e.printStackTrace();
                }
            }
        }
        %>
    </table>
</div>

<hr>
<div class="container2"> 
    <div class="form-wrapper2"> 
        <form action="ordersave.jsp" method="post"> 
            <!-- 表单内容 --> 
            <label for="dish_id">餐品id:</label> 
            <input type="text" id="dish_id" name="dish_id" min="1" required readonly> 
            <label for="name">餐品名称:</label> 
            <input type="text" id="name" name="name" required readonly>
            <label for="price">价格:</label> 
            <input type="text" id="price" name="price" min="1" required readonly>
            <br><label for="amount">数量：</label> 
            <input type="number" id="amount" name="amount" min="1" required> 
            <input type="hidden" id="table_id" name="table_id" value="<%= table_id %>" required> 
            <input type="hidden" id="restaurant_id" name="restaurant_id" value="<%= restaurant_id %>" required> 
            <input type="hidden" id="status" name="status" value="waiting" required>
            <input type="hidden" id="pay" name="pay" value="未支付" required>
            <button type="submit" name="btn" value="添加到购物车">添加到购物车</button>
        </form> 
    </div> 
</div>

<script>
function fillform(row) {
    var dish_id = row.cells[0].innerText;
    var name = row.cells[1].innerText;
    var price = row.cells[2].innerText;
    
    document.getElementById('dish_id').value = dish_id;
    document.getElementById('name').value = name;
    document.getElementById('price').value = price;
    // 其他需要填充的表单字段...
}


function fillform(row) {
    var dish_id = row.cells[0].innerText;
    var name = row.cells[1].innerText;
    var price = row.cells[2].innerText;
    
    document.getElementById('dish_id').value = dish_id;
    document.getElementById('name').value = name;
    document.getElementById('price').value = price;
}

</script>


</body>
</html>